﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Infrastructure.Entities;

namespace AP.Web.Controllers
{
    public class NewsController : Controller
    {
        IArticle _article;
        IChannel _channel;
        IArticleCategory _articleCategory;
        public NewsController(IArticle article, IChannel channel, IArticleCategory articleCategory)
        {
            _article = article;
            _channel = channel;
            _articleCategory = articleCategory;
        }

        public ActionResult Index(int? categoryId)
        {
            IEnumerable<cms_Article> articleList;
            if ((categoryId ?? 0) > 0)
            {
                articleList = _article.GetAll().Where(p => p.CategoryId == categoryId).OrderByDescending(p => p.ModifyTime).ToList();

            }
            else
            {
                articleList = _article.GetAll().OrderByDescending(p => p.ModifyTime).ToList();
            }

            return View(articleList);
        }
        public ActionResult ViewDetails(int? articleId)
        {
            cms_Article model = _article.GetAll().Where(p => p.ID == articleId).FirstOrDefault();
            return View(model);

        }
    }
}
